<#assign pojo=oneToManyPojo.getOne()>
<#assign many=oneToManyPojo.getMany()>
<#assign ones=oneToManyPojo.getOnes()>
<#assign fields=pojo.getFilterdPojoFields()>
<#assign declarationName = pojo.importType(pojo.getDeclarationName())>
<#assign declarationNameFirstLetterLower = pojo.importType(pojo.getDeclarationNameFirstLetterLower())>
<#assign realPackageAndClassPath = "${pojo.getRealPackageAndClassPath()}">
<#assign masterid = pojo.getDeclarationNameFirstLetterLower()+"Id">
import { request } from '../../utils'

const base_url = '/builder-api/${pojo.getDeclarationNameFirstLetterLower()}/';

get${declarationName}ById = function  (id) {
return request({
url: base_url + id,
method: 'get',
data: {id: id}
})
}

save${declarationName} = function  (entity) {
if (entity != null) {
return request({
url: base_url,
method: 'post',
data: entity
})
} else {
throw new Error("保存的信息不能为空");
}
}

update${declarationName} = function  (entity) {
if (entity != null) {
if (entity.id != null) {
return request({
url: base_url+entity.id,
method: 'put',
data: entity
})
}else{
throw new Error("保存的信息id必须为空");
}
} else {
throw new Error("保存的信息不能为空");
}
}

update${declarationName}Batch = function  (keys,entity) {
let ids_ = '';
if (keys instanceof Array) {
ids_ = keys.join(',');
} else if (typeof keys === 'string'  ) {
ids_ = keys
} else {
throw new Error("不支持的主键类型");
}
if (entity != null) {
return request({
url: base_url + ids_,
method: 'patch',
data: entity
})
} else {
throw new Error("保存的信息不能为空");
}
}

delete${declarationName} = function  (entity) {
if (entity != null) {
if (entity.id != null) {
return request({
url: base_url + entity.id,
method: 'delete'
})
} else {
throw new Error("删除的数据还没有保存");
}
} else {
throw new Error("保存的信息不能为空");
}
}

delete${declarationName}s = function  (ids) {
if (ids != null && ids.length > 0) {
return request({
url: base_url + ids,
method: 'delete'
})
} else {
throw new Error("保存的信息不能为空");
}
}

find${declarationName}ByList = function  (params) {
return request({
url: base_url ,
method: 'get',
data: params
})
}
find${declarationName}ByPage = function  (params) {
return request({
url: base_url + 'findByPage',
method: 'get',
data: params
})
}

<#foreach child in many>
    <#assign childdeclarationName = child.importType(child.getDeclarationName())>
    <#assign childdeclarationNameFirstLetterLower = pojo.importType(child.getDeclarationNameFirstLetterLower())>
    <#assign tempchild=child>

save${childdeclarationName} = function  (${declarationNameFirstLetterLower}Id,entity) {
if (entity != null) {
return request({
url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id,
method: 'post',
data: entity
})
} else {
throw new Error("保存的信息不能为空");
}
}

update${childdeclarationName} = function  (${declarationNameFirstLetterLower}Id,entity) {
if (entity != null) {
if (entity.id != null) {
return request({
url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id+'/'+ entity.id,
method: 'put',
data: entity
})
}else{
throw new Error("保存的信息id必须为空");
}
} else {
throw new Error("保存的信息不能为空");
}
}

update${childdeclarationName}Batch = function  (${declarationNameFirstLetterLower}Id,keys,entity) {
let ids_ = '';
if (keys instanceof Array) {
ids_ = keys.join(',');
} else if (typeof keys === 'string'  ) {
ids_ = keys
} else {
throw new Error("不支持的主键类型");
}
if (entity != null) {
return request({
url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id+'/'+ ids_,
method: 'patch',
data: entity
})
} else {
throw new Error("保存的信息不能为空");
}
}

delete${childdeclarationName} = function  (${declarationNameFirstLetterLower}Id,entity) {
if (entity != null) {
if (entity.id != null) {
return request({
url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id+'/'+ entity.id,
method: 'delete'
})
} else {
throw new Error("删除的数据还没有保存");
}
} else {
throw new Error("保存的信息不能为空");
}
}

delete${childdeclarationName}s = function  (${declarationNameFirstLetterLower}Id,ids) {
if (entity != null && ids.length > 0) {
return request({
url: base_url + 'project/' + ${declarationNameFirstLetterLower}Id + '/' + ids,
method: 'delete'
})
} else {
throw new Error("保存的信息不能为空");
}
}
    <#if child.getRelation() == "MANY_DEFAULT">
    get${childdeclarationName}ById = function  (${declarationNameFirstLetterLower}Id,id) {
    return request({
    url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id+'/'+  id,
    method: 'get',
    data: {id: id}
    })
    }

    find${childdeclarationName}ByList = function  (${declarationNameFirstLetterLower}Id,params) {
    return request({
    url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id,
    method: 'get',
    data: params
    })
    }
    find${childdeclarationName}ByPage = function  (${declarationNameFirstLetterLower}Id,params) {
    return request({
    url: base_url + '${childdeclarationNameFirstLetterLower}/'+${declarationNameFirstLetterLower}Id+ '/findByPage',
    method: 'get',
    data: params
    })
    }
    </#if>
</#foreach>
<#foreach child in ones>
</#foreach>